package ungdung_quanlymathang;

import com.example.quanly_mathang.R;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;


public class Ac_dangnhap extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dangnhap);
       
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    public void dangnhap(View v){
    	EditText ten=(EditText)findViewById(R.id.editText1);
        EditText mk=(EditText)findViewById(R.id.editText2);
        Cosodulieu csdl=new Cosodulieu(this);
        Cursor c=csdl.lay_nguoidung(mk.getText().toString());
        if(c!=null){
          if(c.moveToFirst()){
            if(ten.getText().toString().equals(c.getString(c.getColumnIndex("ten")))){
        	Intent it=new Intent(this.getApplicationContext(),Ac_danhsachmathang.class);
        	Bundle bd=new Bundle();
        	bd.putString("ten_nguoidung",ten.getText().toString());
        	bd.putString("matkhau", mk.getText().toString());
        	bd.putString("idnd",c.getString(c.getColumnIndex("id")) );
        	it.putExtras(bd);
        	startActivity(it);
        	c.close();}
            }
        }
        if(c.getCount()==0) {
        	AlertDialog.Builder al=new AlertDialog.Builder(this);
    		al.setMessage("Nhập sai tên người dùng và mật khẩu!\n Hãy nhập lại").setPositiveButton("OK", null).show();
    	}
    }
    public void ac_dangky(View v){
    	Intent it=new Intent(this.getApplicationContext(),Ac_dangky.class);
    	startActivity(it);
    }
    
    
}
